import request from '../../utils/request';

export interface Property {
  propertyId?: number;
  propertyName?: string;
  valueId?: number;
  valueName?: string;
}

export interface Sku {
  id?: number;
  name?: string;
  spuId?: number;
  properties?: Property[];
  price?: number | string;
  marketPrice?: number | string;
  costPrice?: number | string;
  barCode?: string;
  picUrl?: string;
  stock?: number;
  weight?: number;
  volume?: number;
  firstBrokeragePrice?: number | string;
  secondBrokeragePrice?: number | string;
  salesCount?: number;
}

export interface Spu {
  id?: number;
  name?: string;
  categoryId?: number;
  keyword?: string;
  unit?: number;
  picUrl?: string;
  sliderPicUrls?: string[];
  introduction?: string;
  deliveryTypes?: number[];
  deliveryTemplateId?: number;
  brandId?: number;
  specType?: boolean;
  subCommissionType?: boolean;
  skus?: Sku[];
  description?: string;
  sort?: number;
  giveIntegral?: number;
  virtualSalesCount?: number;
  recommendHot?: boolean;
  recommendBenefit?: boolean;
  recommendBest?: boolean;
  recommendNew?: boolean;
  recommendGood?: boolean;
  activityOrders?: number[];
}

export interface ProductCategoryVO {
  id: number;
  parentId: number;
  name: string;
  picUrl: string;
  sort: number;
  description: string;
  status: number;
  createTime: string;
  children?: ProductCategoryVO[];
}

export interface ProductBrandVO {
  id: number;
  name: string;
  picUrl: string;
  sort: number;
  description: string;
  status: number;
  createTime: string;
}

// 商品管理 API
export const ProductApi = {
  // SPU 相关
  getSpuPage: async (params: any) => {
    return await request.get('/product/spu/page', { params });
  },

  getSpu: async (id: number) => {
    return await request.get(`/product/spu/get?id=${id}`);
  },

  createSpu: async (data: Spu) => {
    return await request.post('/product/spu/create', data);
  },

  updateSpu: async (data: Spu) => {
    return await request.put('/product/spu/update', data);
  },

  deleteSpu: async (id: number) => {
    return await request.delete(`/product/spu/delete?id=${id}`);
  },

  // 商品分类相关
  getCategoryList: async (params?: any) => {
    return await request.get('/product/category/list', { params });
  },

  getCategory: async (id: number) => {
    return await request.get(`/product/category/get?id=${id}`);
  },

  createCategory: async (data: ProductCategoryVO) => {
    return await request.post('/product/category/create', data);
  },

  updateCategory: async (data: ProductCategoryVO) => {
    return await request.put('/product/category/update', data);
  },

  deleteCategory: async (id: number) => {
    return await request.delete(`/product/category/delete?id=${id}`);
  },

  // 商品品牌相关
  getBrandPage: async (params: any) => {
    return await request.get('/product/brand/page', { params });
  },

  getBrand: async (id: number) => {
    return await request.get(`/product/brand/get?id=${id}`);
  },

  createBrand: async (data: ProductBrandVO) => {
    return await request.post('/product/brand/create', data);
  },

  updateBrand: async (data: ProductBrandVO) => {
    return await request.put('/product/brand/update', data);
  },

  deleteBrand: async (id: number) => {
    return await request.delete(`/product/brand/delete?id=${id}`);
  },

  // 获取商品简单列表
  getSpuSimpleList: async () => {
    return await request.get('/product/spu/simple-list');
  }
};